import { HoomEventCenter } from "./HoomEventCenter";
import { EventType } from "./Model.RoomEvent";
import { RingPolicy } from "./ChangeColorPolicy";
import { ColorType } from './Model.ShadowType';
import { Logger } from '../Util/Logger';
import { AudioResource } from "../Core/Resource.Audio";
import { AudioType } from "../Core/AudioType";

const { ccclass, property } = cc._decorator;

@ccclass
export default class HomeView extends cc.Component {

   private playBtn: cc.Node;
   private sideNode: cc.Node;
   private ringNode: cc.Node;
   
   private toggle_wx: cc.Toggle;
   onLoad() {
      this.sideNode = this.node.find("content/side");
      this.ringNode = this.node.find("content/ring");
      this.playBtn = this.node.find("buttom/playButton");
      this.toggle_wx = this.node.getChildByName('xieyi').getChildByName('choose').getComponent(cc.Toggle);
      this.playBtn.on("click", this.onPlay, this);
      this.loadResource();

   }
   private onPlay() {


      if (this.toggle_wx.isChecked) {
         AudioResource.playByAudioType(AudioType.btn);
         cc.director.preloadScene("3.Room");
         this.sideNode.active = true;
         this.ringNode.active = false;
   
         //动画
         for (let item of this.sideNode.children) {
            let newPosition = item.position.mulSelf(5);
            cc.tween(item).to(0.5, { position: newPosition }, { easing: "circInOut" }).start();
         }
         //btn
         cc.tween(this.playBtn).by(0.5, { position: cc.v2(0, -400) }, { easing: "circInOut" }).start();
   
         this.scheduleOnce((dt) => {
            RingPolicy.setDeafult();
            HoomEventCenter.offAll();
            cc.director.loadScene("3.Room");
         }, 0.55);
         //


     }else{
      console.log("进行登陆");
      
         if (cc.sys.platform == cc.sys.ANDROID) {
             jsb.reflection.callStaticMethod("org/cocos2dx/javascript/AppActivity", "showTip", "()V");
         }
     }


      // AudioResource.playByAudioType(AudioType.btn);
      // cc.director.preloadScene("3.Room");
      // this.sideNode.active = true;
      // this.ringNode.active = false;

      // //动画
      // for (let item of this.sideNode.children) {
      //    let newPosition = item.position.mulSelf(5);
      //    cc.tween(item).to(0.5, { position: newPosition }, { easing: "circInOut" }).start();
      // }
      // //btn
      // cc.tween(this.playBtn).by(0.5, { position: cc.v2(0, -400) }, { easing: "circInOut" }).start();

      // this.scheduleOnce((dt) => {
      //    RingPolicy.setDeafult();
      //    HoomEventCenter.offAll();
      //    cc.director.loadScene("3.Room");
      // }, 0.55);
      // //
   }

   wx_yh(){
      if(cc.sys.ANDROID)
      if (cc.sys.platform == cc.sys.ANDROID) {
          console.log("wx_yh");
          
          jsb.reflection.callStaticMethod("org/cocos2dx/javascript/AppActivity", "openXieYi", "()V");
      }
  }

  wx_ys(){

      console.log("wx_ys");
      
      if (cc.sys.platform == cc.sys.ANDROID) {
          
          jsb.reflection.callStaticMethod("org/cocos2dx/javascript/AppActivity", "openYinSi", "()V");
      }
  }



   /**加载音频 */
   private loadResource() {
      cc.loader.loadResDir("/audio", cc.AudioClip, this.audioProgress.bind(this), this.audioComplete.bind(this));
   }

   private audioComplete(err, textures) {
      Logger.info(textures.name);
      AudioResource.cacheAudioClip(textures);
   }

   private audioProgress(completeCount: number, totalCount: number, res) {
      Logger.info("completeCount:" + completeCount, "totalCount:" + totalCount);
   }

}
